home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / xpcom / nsProxyEvent.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  7KB  |  184 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  26.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. #ifndef __nsProxyEvent_h_
  39. #define __nsProxyEvent_h_
  40.  
  41. #include "nsCOMPtr.h"
  42. #include "nsAutoPtr.h"
  43. #include "nscore.h"
  44. #include "nsISupports.h"
  45. #include "nsIFactory.h"
  46.  
  47. #include "nsIEventQueueService.h"
  48. #include "nsIEventQueue.h"
  49. #include "plevent.h"
  50. #include "prtypes.h"
  51. #include "xptcall.h"
  52. #include "xptinfo.h"
  53.     
  54. class nsProxyObjectCallInfo;
  55.  
  56. #define PROXY_SYNC    0x0001  // acts just like a function call.
  57. #define PROXY_ASYNC   0x0002  // fire and forget.  This will return immediately and you will lose all return information.
  58. #define PROXY_ALWAYS  0x0004   // ignore check to see if the eventQ is on the same thread as the caller, and alway return a proxied object.
  59.  
  60. //#define AUTOPROXIFICATION
  61.  
  62. // WARNING about PROXY_ASYNC:  
  63. //
  64. // If the calling thread goes away, any function which accesses the calling stack 
  65. // will blow up.
  66. //
  67. //  example:
  68. //
  69. //     myFoo->bar(&x)
  70. //
  71. //     ... thread goes away ...
  72. //
  73. //    bar(PRInt32 *x)
  74. //    {
  75. //         *x = 0;   <-----  You will blow up here.
  76. //
  77. //   
  78. //  So what gets saved?  
  79. //
  80. //  You can safely pass base types by value.  You can also pass interface pointers.
  81. //  I will make sure that the interface pointers are addrefed while they are being 
  82. //  proxied.  You can also pass string and wstring.  These I will copy and free.
  83. //
  84. //  I do **NOT** copy arrays or strings with size.  If you are using these either
  85. //  change your interface, or contact me about this feature request.
  86.  
  87.  
  88.  
  89.  
  90. class nsProxyObject
  91. {
  92. public:
  93.     nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, nsISupports *realObject);
  94.     nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, const nsCID &aClass,  nsISupports *aDelegate,  const nsIID &aIID);
  95.  
  96.     void AddRef();
  97.     void Release();
  98.  
  99.                         ~nsProxyObject();
  100.  
  101.     nsresult            Post( PRUint32            methodIndex, 
  102.                               nsXPTMethodInfo   * info, 
  103.                               nsXPTCMiniVariant * params, 
  104.                               nsIInterfaceInfo  * interfaceInfo);
  105.     
  106.     nsresult            PostAndWait(nsProxyObjectCallInfo *proxyInfo);
  107.     nsISupports*        GetRealObject() const { return mRealObject; }
  108.     nsIEventQueue*      GetQueue() const { return mDestQueue; }
  109.     PRInt32             GetProxyType() const { return mProxyType; }
  110.  
  111.     friend class nsProxyEventObject;
  112. private:
  113.     
  114.     nsAutoRefCnt              mRefCnt;
  115.  
  116.     PRInt32                   mProxyType;
  117.     
  118.     nsCOMPtr<nsIEventQueue>   mDestQueue;        /* destination queue */
  119.     
  120.     nsCOMPtr<nsISupports>     mRealObject;       /* the non-proxy object that this event is referring to. 
  121.                                                     This is a strong ref. */
  122.     nsCOMPtr<nsIEventQueueService> mEventQService;
  123.  
  124.     nsresult convertMiniVariantToVariant(nsXPTMethodInfo   * methodInfo, 
  125.                                          nsXPTCMiniVariant * params, 
  126.                                          nsXPTCVariant     **fullParam, 
  127.                                          uint8 *paramCount);
  128.  
  129. };
  130.  
  131.  
  132. class nsProxyObjectCallInfo
  133. {
  134. public:
  135.     
  136.     nsProxyObjectCallInfo(nsProxyObject* owner,
  137.                           nsXPTMethodInfo *methodInfo,
  138.                           PRUint32 methodIndex, 
  139.                           nsXPTCVariant* parameterList, 
  140.                           PRUint32 parameterCount, 
  141.                           PLEvent *event);
  142.  
  143.     ~nsProxyObjectCallInfo();
  144.  
  145.     PRUint32            GetMethodIndex() const { return mMethodIndex; }
  146.     nsXPTCVariant*      GetParameterList() const { return mParameterList; }
  147.     PRUint32            GetParameterCount() const { return mParameterCount; }
  148.     PLEvent*            GetPLEvent() const { return mEvent; }
  149.     nsresult            GetResult() const { return mResult; }
  150.     nsProxyObject*      GetProxyObject() const { return mOwner; }
  151.     
  152.     PRBool              GetCompleted();
  153.     void                SetCompleted();
  154.     void                PostCompleted();
  155.  
  156.     void                SetResult(nsresult rv) {mResult = rv; }
  157.     
  158.     nsIEventQueue*      GetCallersQueue();
  159.     void                SetCallersQueue(nsIEventQueue* queue);
  160.  
  161. private:
  162.     
  163.     nsresult         mResult;                    /* this is the return result of the called function */
  164.     nsXPTMethodInfo *mMethodInfo;
  165.     PRUint32         mMethodIndex;               /* which method to be called? */
  166.     nsXPTCVariant   *mParameterList;             /* marshalled in parameter buffer */
  167.     PRUint32         mParameterCount;            /* number of params */
  168.     PLEvent         *mEvent;                     /* the current plevent */       
  169.     PRInt32          mCompleted;                 /* is true when the method has been called. */
  170.        
  171.     nsCOMPtr<nsIEventQueue>  mCallersEventQ;     /* this is the eventQ that we must post a message back to 
  172.                                                     when we are done invoking the method (only PROXY_SYNC). 
  173.                                                   */
  174.  
  175.     nsRefPtr<nsProxyObject>   mOwner;            /* this is the strong referenced nsProxyObject */
  176.    
  177.     void RefCountInInterfacePointers(PRBool addRef);
  178.     void CopyStrings(PRBool copy);
  179.  
  180. };
  181.  
  182.  
  183. #endif
  184.